package com.googlecode.battleofendor.jme;

import com.googlecode.battleofendor.synchroniation.Player;
import com.googlecode.battleofendor.synchroniation.messages.PositionInfo;
import com.jme.scene.Controller;
import com.jme.scene.Spatial;

public class LinearPoolMover extends Controller {

	private static final long serialVersionUID = -834661777013946127L;

	private Spatial spatial;
	
	private Player pool;
	
	public LinearPoolMover(Spatial spatial, Player pool) {
		this.spatial = spatial;
		this.pool = pool;
	}
	
	@Override
	public void update(float ignore) {
		PositionInfo info = pool.getPositionInfo(spatial.getName());
		
		float time = (pool.currentTimeMillis() - info.time) / 1000.0f;
		float abs = info.speed * time;
		
		spatial.setLocalTranslation(
				info.x + info.dirx * abs,
				info.y + info.diry * abs,
				info.z + info.dirz * abs);
	}

}
